<?php

include 'DBconn.php';

class QuotationMaster {

	public function quotationListPopup() {
        $query = "Select qh.serialnumber,qh.current_rate,qh.cre_datetime,qh.quotation_code,qd.detserialnumber,qd.pro_serialnumber_fk,qd.pro_qty,qd.price_per_unit,qd.pro_total_price,ph.pro_name,ph.part_number,ph.pro_description,ph.model_no,
		qd.pro_detserialnumber,qd.base_currency_detserialnumber_fk,cd.currency_value,prd.listprice,prd.currency_serialnumber,prd.markup_type,prd.listprice,prd.discount,prd.markup1,prd.markup2,prd.markup3,prd.markup4,prd.markup5,prd.markup6,prd.default_price from quotation_details as qd 
		LEFT JOIN product_details as prd ON prd.pro_detserialnumber=qd.pro_detserialnumber LEFT JOIN product_header as ph ON ph.serialnumber=qd.pro_serialnumber_fk and ph.activestatus=1 LEFT JOIN quotation_header as qh
		ON qh.activestatus=1 and qh.serialnumber=qd.quotation_serialnumber_fk  LEFT JOIN currency_detail as cd ON cd.detserialnumber=qd.base_currency_detserialnumber_fk and cd.to_currency_fk=prd.currency_serialnumber where 
		qd.activestatus=1 ORDER BY qd.quotation_serialnumber_fk";
        $result = mysql_query($query) or die(mysql_error());
        $ret = array();
        while ($row = mysql_fetch_object($result)) {
				$temp = new VoQuotationPopupList;
				$temp->quot_serialnumber = (int)$row->serialnumber;
                $temp->quotation_code = $row->quotation_code;
				$temp->quot_detserialnumber = (int) $row->detserialnumber;
                $temp->pro_serialnumber_fk = (int) $row->pro_serialnumber_fk;
				$temp->pro_detserialnumber = (int) $row->pro_detserialnumber;
				$temp->base_currency_detserialnumber_fk = (int) $row->base_currency_detserialnumber_fk;
                $temp->pro_qty = (double) $row->pro_qty;
                $temp->price_per_unit = round(($row->price_per_unit * $row->current_rate),4);
				$temp->pro_name = $row->pro_name;
				$temp->part_number = $row->part_number;
				$temp->pro_description = $row->pro_description;
				$temp->model_no = $row->model_no;
                $temp->isSelected = false;
				
				$m1 = (double)$row->markup1;
				$m2 = (double)$row->markup2;
				$m3 = (double)$row->markup3;
				$m4 = (double)$row->markup4;
				$m5 = (double)$row->markup5;
				$m6 = (double)$row->markup6;
				
				$listprice = (double)$row->listprice;
				$discount = (double)$row->discount;
				
				$netprice = round(($listprice - (($discount/100)*$listprice)),2);
				
				$base_currency_value =(double)$row->currency_value;
				
				$costPrice = $netprice * $base_currency_value;
				
				$temp->sgd_listprice = round((($listprice - ($listprice * $discount/100))* $base_currency_value),4);
				
				$price1=0;
				$price2=0;
				$price3=0;
				$price4=0;
				$price5=0;
				$price6=0;
			
			if($row->markup_type!='Net Markup')
			 {
				$price1 = round(($costPrice/(1-($m1/100))),4);
				$price2 = round(($costPrice/(1-($m2/100))),4);
				$price3 = round(($costPrice/(1-($m3/100))),4);
				$price4 = round(($costPrice/(1-($m4/100))),4);
				$price5 = round(($costPrice/(1-($m5/100))),4);
				$price6 = round(($costPrice/(1-($m6/100))),4);
			 }else{
				$price1 = round(($costPrice*(1+($m1/100))),4);
				$price2 = round(($costPrice*(1+($m2/100))),4);
				$price3 = round(($costPrice*(1+($m3/100))),4);
				$price4 = round(($costPrice*(1+($m4/100))),4);
				$price5 = round(($costPrice*(1+($m5/100))),4);
				$price6 = round(($costPrice*(1+($m6/100))),4);
			 }
			 
			$priceList = array();

            $priceObj1 = new VOPrice();
            $priceObj1->sgd_price = (double)$price1;
			$priceObj1->other_price = (double)$price1;
            $priceObj1->hilight = 0;
            if ($row->default_price == 'Price A') {
                $priceObj1->hilight = 1;
            }
            $priceList[] = $priceObj1;

            $priceObj2 = new VOPrice();
            $priceObj2->sgd_price = (double)$price2;
			$priceObj2->other_price = (double)$price2;
            $priceObj2->hilight = 0;
            if ($row->default_price == 'Price B') {
                $priceObj2->hilight = 1;
            }
            $priceList[] = $priceObj2;

            $priceObj3 = new VOPrice();
            $priceObj3->sgd_price = (double)$price3;
			$priceObj3->other_price = (double)$price3;
            $priceObj3->hilight = 0;
            if ($row->default_price == 'Price C') {
                $priceObj3->hilight = 1;
            }
            $priceList[] = $priceObj3;

            $priceObj4 = new VOPrice();
            $priceObj4->sgd_price = (double)$price4;
			$priceObj4->other_price = (double)$price4;
            $priceObj4->hilight = 0;
            if ($row->default_price == 'Price D') {
                $priceObj4->hilight = 1;
            }
            $priceList[] = $priceObj4;

            $priceObj5 = new VOPrice();
            $priceObj5->sgd_price = (double)$price5;
			$priceObj5->other_price = (double)$price5;
            $priceObj5->hilight = 0;
            if ($row->default_price == 'Price E') {
                $priceObj5->hilight = 1;
            }
            $priceList[] = $priceObj5;

            $priceObj6 = new VOPrice();
            $priceObj6->sgd_price = (double)$price6;
			$priceObj6->other_price = (double)$price6;
            $priceObj6->hilight = 0;
            if ($row->default_price == 'Price F') {
                $priceObj6->hilight = 1;
            }
            $priceList[] = $priceObj6;

            $temp->price_list = $priceList;
            $temp->default_price = $row->default_price;
			
            $ret[] = $temp;
        }

        return $ret;
    }
	
    public function addNewquotation($VObject) {
        $enqCode = $this->generatequotationCode();
        $query = "insert into quotation_header(quotation_code,total_amount,total_qty,quotation_date,quot_term,quot_gst,currency_serialnumber_fk,current_rate,quotation_remarks,cre_userid_fk,cre_datetime,activestatus) values ('$enqCode','$VObject->total_amount','$VObject->total_qty','$VObject->quotation_date','$VObject->quot_term','$VObject->quot_gst','$VObject->currency_serialnumber_fk','$VObject->current_rate','$VObject->quotation_remarks','$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
        $s = mysql_query($query) or die(mysql_error());
        if ($s) {
            $last_id = mysql_insert_id();
            foreach ($VObject->customer_serialnumber_fk as $r => $value) {
                $query1 = "insert into quotation_cust_details(quotation_serialnumber_fk,customer_serialnumber_fk,cre_userid_fk,cre_datetime,activestatus)values ('$last_id','$value','$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
                $s1 = mysql_query($query1) or die(mysql_error());
            }
            foreach ($VObject->pro_serialnumber_fk as $r => $value) {
				$pro_detserialnumber = mysql_real_escape_string($VObject->pro_detserialnumber[$r]);
				$base_currency_detserialnumber_fk = mysql_real_escape_string($VObject->base_currency_detserialnumber_fk[$r]);
                $price_per_unit = mysql_real_escape_string($VObject->price_per_unit[$r]);
                $pro_qty = mysql_real_escape_string($VObject->pro_qty[$r]);
                $pro_total_price = mysql_real_escape_string($VObject->pro_total_price[$r]);
                $query2 = "insert into quotation_details(quotation_serialnumber_fk,pro_serialnumber_fk,pro_detserialnumber,base_currency_detserialnumber_fk,pro_qty,price_per_unit,pro_total_price,cre_userid_fk,cre_datetime,activestatus) values('$last_id','$value','$pro_detserialnumber','$base_currency_detserialnumber_fk','$pro_qty','$price_per_unit','$pro_total_price','$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
                mysql_query($query2) or die(mysql_error());
            }
        }
//	return $this->getquotationByCode($last_id);
    }

    public function editquotation($VObject) {
        $query = "update quotation_header set quotation_code='$VObject->quotation_code',total_amount='$VObject->total_amount',total_qty='$VObject->total_qty',quotation_date='$VObject->quotation_date',quotation_remarks='$VObject->quotation_remarks',quot_term='$VObject->quot_term',quot_gst='$VObject->quot_gst',currency_serialnumber_fk='$VObject->currency_serialnumber_fk',current_rate='$VObject->current_rate' where serialnumber='$VObject->serialnumber'";
        $s = mysql_query($query) or die(mysql_error());
        if ($s) {
            mysql_query("update quotation_cust_details set activestatus=0 where quotation_serialnumber_fk='$VObject->serialnumber'") or die(mysql_error());
            mysql_query("update quotation_details set activestatus=0 where quotation_serialnumber_fk='$VObject->serialnumber'") or die(mysql_error());
            foreach ($VObject->customer_serialnumber_fk as $r => $value) {
                $query1 = "insert into quotation_cust_details(quotation_serialnumber_fk,customer_serialnumber_fk,cre_userid_fk,cre_datetime,activestatus)values ('$VObject->serialnumber','$value','$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
                $s1 = mysql_query($query1) or die(mysql_error());
            }
            foreach ($VObject->pro_serialnumber_fk as $r => $value) {
				$pro_detserialnumber = mysql_real_escape_string($VObject->pro_detserialnumber[$r]);
				$base_currency_detserialnumber_fk = mysql_real_escape_string($VObject->base_currency_detserialnumber_fk[$r]);
                $price_per_unit = mysql_real_escape_string($VObject->price_per_unit[$r]);
                $pro_qty = mysql_real_escape_string($VObject->pro_qty[$r]);
                $pro_total_price = mysql_real_escape_string($VObject->pro_total_price[$r]);
                $query2 = "insert into quotation_details(quotation_serialnumber_fk,pro_serialnumber_fk,pro_detserialnumber,base_currency_detserialnumber_fk,pro_qty,price_per_unit,pro_total_price,cre_userid_fk,cre_datetime,activestatus) values('$VObject->serialnumber','$value','$pro_detserialnumber','$base_currency_detserialnumber_fk','$pro_qty','$price_per_unit','$pro_total_price','$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
                mysql_query($query2) or die(mysql_error());
            }
        }
        //return $this->getquotationByCode($VObject->serialnumber);
    }

    public function deletequotation($serialnumber) {
        $query1 = ("update quotation_header set activestatus=0 where serialnumber='$serialnumber'") or die(mysql_error());
        mysql_query($query1) or die(mysql_error());
        $query2 = ("update quotation_cust_details set activestatus=0 where quotation_serialnumber_fk='$serialnumber'") or die(mysql_error());
        mysql_query($query2) or die(mysql_error());
        $query3 = ("update quotation_details set activestatus=0 where quotation_serialnumber_fk='$serialnumber'") or die(mysql_error());
        mysql_query($query3) or die(mysql_error());
        return $serialnumber;
    }

    public function generatequotationCode() {
        $query = "select quotation_code from quotation_header order by serialnumber desc limit 1 ";
        $result = mysql_query($query) or die(mysql_error());
        if (mysql_num_rows($result)) {
            $row = mysql_fetch_array($result);
            $str = explode("QUT", $row[0]);
            $num = intval($str[1]);
            $res = "QUT" . ++$num;
        } else {
            $res = 'QUT1001';
        }
        return $res;
    }

    public function getAllquotations() {
        $ret = array();
        $query = "Select *,IF((Select count(*) from quot_det_sc where activestatus=1 and quot_detserialnumber_fk IN(Select detserialnumber from quotation_details as qd where qd.activestatus=1 and qd.quotation_serialnumber_fk=qh.serialnumber)) > 0,1,0) as quot_edit from quotation_header as qh where qh.activestatus=1";
        $s = mysql_query($query) or die(mysql_error());
        while ($row = mysql_fetch_object($s)) {
            $temp = new VoQuotation();			
            $temp->serialnumber = (int) $row->serialnumber;
            $temp->quotation_code = $row->quotation_code;
            $temp->total_amount = (double) $row->total_amount;
            $temp->total_qty = (double) $row->total_qty;
			$temp->quot_term = (int) $row->quot_term;
			$temp->quot_gst = (double) $row->quot_gst;
			$temp->currency_serialnumber_fk = (int) $row->currency_serialnumber_fk;
			$temp->current_rate = (double) $row->current_rate;
            $temp->quotation_date = date("d-m-Y", strtotime($row->quotation_date));
            $temp->quotation_remarks = $row->quotation_remarks;
            $temp->cre_userid_fk = (int) $row->cre_userid_fk;
            $temp->cre_datetime = $row->cre_datetime;
            $temp->activestatus = (boolean) $row->activestatus;
			$temp->quot_edit = (int) $row->quot_edit;
			
            $query1 = "select que_cus_serialnumber,customer_serialnumber_fk from quotation_cust_details where quotation_serialnumber_fk='$row->serialnumber' and activestatus=1";
            $s1 = mysql_query($query1) or die(mysql_error());
            while ($row1 = mysql_fetch_object($s1)) {
                $temp->que_cus_serialnumber[] = (int) $row1->que_cus_serialnumber;
                $temp->customer_serialnumber_fk[] = (int) $row1->customer_serialnumber_fk;
            }
			
            $query2 = "Select qd.detserialnumber,qd.quotation_serialnumber_fk,qd.pro_serialnumber_fk,qd.pro_qty,qd.price_per_unit,qd.pro_total_price,ph.pro_name,ph.part_number,ph.pro_description,ph.model_no,
			qd.pro_detserialnumber,qd.base_currency_detserialnumber_fk,cd.currency_value,prd.currency_serialnumber,prd.markup_type,prd.listprice,prd.discount,prd.markup1,prd.markup2,prd.markup3,prd.markup4,prd.markup5,prd.markup6,prd.default_price from quotation_details as qd 
			LEFT JOIN product_details as prd ON prd.pro_detserialnumber=qd.pro_detserialnumber LEFT JOIN product_header as ph ON ph.serialnumber=qd.pro_serialnumber_fk and ph.activestatus=1 LEFT JOIN currency_detail as cd ON cd.detserialnumber=qd.base_currency_detserialnumber_fk
			and cd.to_currency_fk=prd.currency_serialnumber where qd.quotation_serialnumber_fk='$row->serialnumber' and qd.activestatus=1";
            $s2 = mysql_query($query2) or die(mysql_error());
            while ($row2 = mysql_fetch_object($s2)) {
                $temp->detserialnumber[] = (int) $row2->detserialnumber;
                $temp->quotation_serialnumber_fk[] = (int) $row2->quotation_serialnumber_fk;
                $temp->pro_serialnumber_fk[] = (int) $row2->pro_serialnumber_fk;
				$temp->pro_detserialnumber[] = (int) $row2->pro_detserialnumber;
				$temp->base_currency_detserialnumber_fk[] = (int) $row2->base_currency_detserialnumber_fk;
                $temp->pro_qty[] = (double) $row2->pro_qty;
                $temp->price_per_unit[] = (double) $row2->price_per_unit;
                $temp->pro_total_price[] = (double) $row2->pro_total_price;
				$temp->pro_name[] = $row2->pro_name;
				$temp->part_number[] = $row2->part_number;
				$temp->pro_description[] = $row2->pro_description;
				$temp->model_no[] = $row2->model_no;
				
				$m1 = (double)$row2->markup1;
				$m2 = (double)$row2->markup2;
				$m3 = (double)$row2->markup3;
				$m4 = (double)$row2->markup4;
				$m5 = (double)$row2->markup5;
				$m6 = (double)$row2->markup6;	
				
				$listprice = (double)$row2->listprice;
				$discount = (double)$row2->discount;
				
				$base_currency_value =(double)$row2->currency_value;
				
				$netprice = round(($listprice - (($discount/100)*$listprice)),2);
			
				$costPrice = $netprice * $base_currency_value;
			    $other_price = $costPrice / $temp->current_rate;
				
				$price1=0;
				$price2=0;
				$price3=0;
				$price4=0;
				$price5=0;
				$price6=0;
				
				$priceQ1=0;
				$priceQ2=0;
				$priceQ3=0;
				$priceQ4=0;
				$priceQ5=0;
				$priceQ6=0;
			
			if($row2->markup_type!='Net Markup')
			 {
				$price1 = round(($costPrice/(1-($m1/100))),4);
				$price2 = round(($costPrice/(1-($m2/100))),4);
				$price3 = round(($costPrice/(1-($m3/100))),4);
				$price4 = round(($costPrice/(1-($m4/100))),4);
				$price5 = round(($costPrice/(1-($m5/100))),4);
				$price6 = round(($costPrice/(1-($m6/100))),4);
			 }else{
				$price1 = round(($costPrice*(1+($m1/100))),4);
				$price2 = round(($costPrice*(1+($m2/100))),4);
				$price3 = round(($costPrice*(1+($m3/100))),4);
				$price4 = round(($costPrice*(1+($m4/100))),4);
				$price5 = round(($costPrice*(1+($m5/100))),4);
				$price6 = round(($costPrice*(1+($m6/100))),4);
			 }
			 
			 $priceQ1 = round(($price1/$temp->current_rate),4);
			 $priceQ2 = round(($price2/$temp->current_rate),4);
			 $priceQ3 = round(($price3/$temp->current_rate),4);
			 $priceQ4 = round(($price4/$temp->current_rate),4);
			 $priceQ5 = round(($price5/$temp->current_rate),4);
			 $priceQ6 = round(($price6/$temp->current_rate),4);
			 
			$priceList = array();

            $priceObj1 = new VOPrice();
            $priceObj1->sgd_price = (double)$price1;
			$priceObj1->other_price = (double)$priceQ1;
            $priceObj1->hilight = 0;
            if ($row2->default_price == 'Price A') {
                $priceObj1->hilight = 1;
                $temp->unitPrice = (double)$priceQ1;
            }
            $priceList[] = $priceObj1;

            $priceObj2 = new VOPrice();
            $priceObj2->sgd_price = (double)$price2;
			$priceObj2->other_price = (double)$priceQ2;
            $priceObj2->hilight = 0;
            if ($row2->default_price == 'Price B') {
                $priceObj2->hilight = 1;
            }
            $priceList[] = $priceObj2;

            $priceObj3 = new VOPrice();
            $priceObj3->sgd_price = (double)$price3;
			$priceObj3->other_price = (double)$priceQ3;
            $priceObj3->hilight = 0;
            if ($row2->default_price == 'Price C') {
                $priceObj3->hilight = 1;
            }
            $priceList[] = $priceObj3;

            $priceObj4 = new VOPrice();
            $priceObj4->sgd_price = (double)$price4;
			$priceObj4->other_price = (double)$priceQ4;
            $priceObj4->hilight = 0;
            if ($row2->default_price == 'Price D') {
                $priceObj4->hilight = 1;
            }
            $priceList[] = $priceObj4;

            $priceObj5 = new VOPrice();
            $priceObj5->sgd_price = (double)$price5;
			$priceObj5->other_price = (double)$priceQ5;
            $priceObj5->hilight = 0;
            if ($row2->default_price == 'Price E') {
                $priceObj5->hilight = 1;
            }
            $priceList[] = $priceObj5;

            $priceObj6 = new VOPrice();
            $priceObj6->sgd_price = (double)$price6;
			$priceObj6->other_price = (double)$priceQ6;
            $priceObj6->hilight = 0;
            if ($row2->default_price == 'Price F') {
                $priceObj6->hilight = 1;
            }
            $priceList[] = $priceObj6;

            $temp->price_list[] = $priceList;
            $temp->default_price[] = $row2->default_price;
			
            }
            $ret[] = $temp;
            mysql_free_result($s1);
            mysql_free_result($s2);
        }
        mysql_free_result($s);
        return $ret;
    }

    public function getquotationByCode($serialnumber) {
        $ret = array();
        $query = "select * from quotation_header where serialnumber='$serialnumber' and activestatus=1";
        while ($row = mysql_fetch_object($s)) 
		{
            $temp = new VoQuotation();
			
            $temp->serialnumber = (int) $row->serialnumber;
            $temp->quotation_code = $row->quotation_code;
            $temp->total_amount = (double) $row->total_amount;
            $temp->total_qty = (double) $row->total_qty;
			$temp->quot_term = (int) $row->quot_term;
			$temp->quot_gst = (double) $row->quot_gst;
			$temp->currency_serialnumber_fk = (int) $row->currency_serialnumber_fk;
			$temp->current_rate = (double) $row->current_rate;
            $temp->quotation_date = date("d-m-Y", strtotime($row->quotation_date));
            $temp->quotation_remarks = $row->quotation_remarks;
            $temp->cre_userid_fk = (int) $row->cre_userid_fk;
            $temp->cre_datetime = $row->cre_datetime;
            $temp->activestatus = (boolean) $row->activestatus;
			
            $query1 = "select que_cus_serialnumber,customer_serialnumber_fk from quotation_cust_details where quotation_serialnumber_fk='$row->serialnumber' and activestatus=1";
            $s1 = mysql_query($query1) or die(mysql_error());
            while ($row1 = mysql_fetch_object($s1)) {
                $temp->que_cus_serialnumber[] = (int) $row1->que_cus_serialnumber;
                $temp->customer_serialnumber_fk[] = (int) $row1->customer_serialnumber_fk;
            }
			
            $query2 = "Select qd.detserialnumber,qd.quotation_serialnumber_fk,qd.pro_serialnumber_fk,qd.pro_qty,qd.price_per_unit,qd.pro_total_price,ph.pro_name,ph.part_number,ph.pro_description,ph.model_no,
			qd.pro_detserialnumber,qd.base_currency_detserialnumber_fk,cd.currency_value,prd.currency_serialnumber,prd.markup_type,prd.listprice,prd.discount,prd.markup1,prd.markup2,prd.markup3,prd.markup4,prd.markup5,prd.markup6,prd.default_price from quotation_details as qd 
			LEFT JOIN product_details as prd ON prd.pro_detserialnumber=qd.pro_detserialnumber LEFT JOIN product_header as ph ON ph.serialnumber=qd.pro_serialnumber_fk and ph.activestatus=1 LEFT JOIN currency_detail as cd ON cd.detserialnumber=qd.base_currency_detserialnumber_fk
			and cd.to_currency_fk=prd.currency_serialnumber where qd.quotation_serialnumber_fk='$serialnumber' and qd.activestatus=1";
            $s2 = mysql_query($query2) or die(mysql_error());
            while ($row2 = mysql_fetch_object($s2)) {
                $temp->detserialnumber[] = (int) $row2->detserialnumber;
                $temp->quotation_serialnumber_fk[] = (int) $row2->quotation_serialnumber_fk;
                $temp->pro_serialnumber_fk[] = (int) $row2->pro_serialnumber_fk;
				$temp->pro_detserialnumber[] = (int) $row2->pro_detserialnumber;
				$temp->base_currency_detserialnumber_fk[] = (int) $row2->base_currency_detserialnumber_fk;
                $temp->pro_qty[] = (double) $row2->pro_qty;
                $temp->price_per_unit[] = (double) $row2->price_per_unit;
                $temp->pro_total_price[] = (double) $row2->pro_total_price;
				$temp->pro_name[] = $row2->pro_name;
				$temp->part_number[] = $row2->part_number;
				$temp->pro_description[] = $row2->pro_description;
				$temp->model_no[] = $row2->model_no;
				
				$m1 = (double)$row2->markup1;
				$m2 = (double)$row2->markup2;
				$m3 = (double)$row2->markup3;
				$m4 = (double)$row2->markup4;
				$m5 = (double)$row2->markup5;
				$m6 = (double)$row2->markup6;	
				
				$listprice = (double)$row2->listprice;
				$discount = (double)$row2->discount;
				
				$base_currency_value =(double)$row2->currency_value;
				
				$netprice = round(($listprice - (($discount/100)*$listprice)),2);
			
				$costPrice = $netprice * $base_currency_value;
			    $other_price = $costPrice / $temp->current_rate;
				
				$price1=0;
				$price2=0;
				$price3=0;
				$price4=0;
				$price5=0;
				$price6=0;
				
				$priceQ1=0;
				$priceQ2=0;
				$priceQ3=0;
				$priceQ4=0;
				$priceQ5=0;
				$priceQ6=0;
			
			if($row2->markup_type!='Net Markup')
			 {
				$price1 = round(($costPrice/(1-($m1/100))),2);
				$price2 = round(($costPrice/(1-($m2/100))),2);
				$price3 = round(($costPrice/(1-($m3/100))),2);
				$price4 = round(($costPrice/(1-($m4/100))),2);
				$price5 = round(($costPrice/(1-($m5/100))),2);
				$price6 = round(($costPrice/(1-($m6/100))),2);
				
				$priceQ1 = round(($other_price/(1-($m1/100))),4);
				$priceQ2 = round(($other_price/(1-($m2/100))),4);
				$priceQ3 = round(($other_price/(1-($m3/100))),4);
				$priceQ4 = round(($other_price/(1-($m4/100))),4);
				$priceQ5 = round(($other_price/(1-($m5/100))),4);
				$priceQ6 = round(($other_price/(1-($m6/100))),4);
				
			 }else{
				$price1 = round(($costPrice*(1+($m1/100))),2);
				$price2 = round(($costPrice*(1+($m2/100))),2);
				$price3 = round(($costPrice*(1+($m3/100))),2);
				$price4 = round(($costPrice*(1+($m4/100))),2);
				$price5 = round(($costPrice*(1+($m5/100))),2);
				$price6 = round(($costPrice*(1+($m6/100))),2);
				
				$priceQ1 = round(($other_price*(1+($m1/100))),4);
				$priceQ2 = round(($other_price*(1+($m2/100))),4);
				$priceQ3 = round(($other_price*(1+($m3/100))),4);
				$priceQ4 = round(($other_price*(1+($m4/100))),4);
				$priceQ5 = round(($other_price*(1+($m5/100))),4);
				$priceQ6 = round(($other_price*(1+($m6/100))),4);
			 }
			 
			 $priceList = array();

            $priceObj1 = new VOPrice();
            $priceObj1->sgd_price = (double)$price1;
			$priceObj1->other_price = (double)$priceQ1;
            $priceObj1->hilight = 0;
            if ($row2->default_price == 'Price A') {
                $priceObj1->hilight = 1;
            }
            $priceList[] = $priceObj1;

            $priceObj2 = new VOPrice();
            $priceObj2->sgd_price = (double)$price2;
			$priceObj2->other_price = (double)$priceQ2;
            $priceObj2->hilight = 0;
            if ($row2->default_price == 'Price B') {
                $priceObj2->hilight = 1;
            }
            $priceList[] = $priceObj2;

            $priceObj3 = new VOPrice();
            $priceObj3->sgd_price = (double)$price3;
			$priceObj3->other_price = (double)$priceQ3;
            $priceObj3->hilight = 0;
            if ($row2->default_price == 'Price C') {
                $priceObj3->hilight = 1;
            }
            $priceList[] = $priceObj3;

            $priceObj4 = new VOPrice();
            $priceObj4->sgd_price = (double)$price4;
			$priceObj4->other_price = (double)$priceQ4;
            $priceObj4->hilight = 0;
            if ($row2->default_price == 'Price D') {
                $priceObj4->hilight = 1;
            }
            $priceList[] = $priceObj4;

            $priceObj5 = new VOPrice();
            $priceObj5->sgd_price = (double)$price5;
			$priceObj5->other_price = (double)$priceQ5;
            $priceObj5->hilight = 0;
            if ($row2->default_price == 'Price E') {
                $priceObj5->hilight = 1;
            }
            $priceList[] = $priceObj5;

            $priceObj6 = new VOPrice();
            $priceObj6->sgd_price = (double)$price6;
			$priceObj6->other_price = (double)$priceQ6;
            $priceObj6->hilight = 0;
            if ($row2->default_price == 'Price F') {
                $priceObj6->hilight = 1;
            }
            $priceList[] = $priceObj6;

            $temp->price_list[] = $priceList;
            $temp->default_price[] = $row2->default_price;
          }
			$ret[] = $temp;
			mysql_free_result($s1);
			mysql_free_result($s2);
		}  
     mysql_free_result($s);
     return $ret;
    }
	
	public function quotSupplierData() {
        $ret = array();
        $query = "select * from quotation_header where activestatus=1";
        $s = mysql_query($query) or die(mysql_error());
        while ($row = mysql_fetch_object($s)) {
            $temp = new voQuotationSupplier();
            $temp->quot_serialnumber = (int) $row->serialnumber;
            $query1 = "select customer_serialnumber_fk	 from quotation_cust_details where activestatus=1 and 
			quotation_serialnumber_fk='$row->serialnumber'";
            $s1 = mysql_query($query1);
            while ($row1 = mysql_fetch_object($s1)) {
                $temp->customer_serialnumber_fk	[] = (int) $row1->customer_serialnumber_fk	;
            }
            $ret[] = $temp;
        }
        return $ret;
    }

}

class VoQuotation {
    var $serialnumber;
    var $quotation_code;
    var $que_cus_serialnumber;
    var $customer_serialnumber_fk;
    var $total_amount;
    var $total_qty;
	var $quot_term;
	var $quot_gst;
	var $currency_serialnumber_fk;
	var $current_rate;
    var $quotation_date;
    var $quotation_remarks;
	var $quot_edit;
    var $detserialnumber;
    var $quotation_serialnumber_fk;
    var $pro_serialnumber_fk;
	var $pro_detserialnumber;
	var $base_currency_detserialnumber_fk;
	var $pro_name;
	var $pro_description;
    var $part_number;
    var $model_no;
	var $default_price;
	var $price_list;
    var $pro_qty;
    var $price_per_unit;
    var $pro_total_price;
    var $cre_userid_fk;
    var $cre_datetime;
    var $activestatus;
}

class VOPrice {
    var $sgd_price;
	var $other_price;
    var $hilight;
}

class voQuotationSupplier {
    var $quot_serialnumber;
    var $customer_serialnumber_fk;
}

class VoQuotationPopupList {
    var $quot_serialnumber;
    var $quotation_code;
	var $quot_detserialnumber;
	var $pro_serialnumber_fk;
	var $pro_detserialnumber;
	var $sgd_listprice;
	var $pro_name;
	var $pro_description;
    var $part_number;
    var $model_no;
	var $default_price;
	var $price_list;
    var $pro_qty;
    var $price_per_unit;
	var $base_currency_detserialnumber_fk;
    var $isSelected;
}

?>